package com.cloudptt.api.product.func.call;


import com.cloudptt.api.product.func.call.single.LaunchCallInfo;
import com.cloudptt.api.product.log.Log;
import com.mcptt.config.model.McIdInfo;
import com.mcptt.db.model.AddrInfo;



public class CallAttr 
{
	public static String THIS_FILE = "CallAttr";
	public static String DEF_CALL_ID_STR = "0-0-0-0";
	public static final int DefaultCallId                         = 0;
	public static final int CallDir_MO 		= 0;  //主叫        	
	public static final int CallDir_MT 		= 1;  //被叫

	public static final int RtcpMsg_Request 		= 1;  //主叫
	public static final int RtcpMsg_Release = 2;  //被叫
	public static final int OpMedia_Resume 		= 1;  //主叫
	public static final int OpMedia_Pause = 0;
	public static final int OpMedia_Add 		= 1;  //主叫
	public static final int OpMedia_Remove = 0;

//	public static final int Func_Self = 31;
//	public static final int Func_Query = 32;

	public static final int McType_McPtt = 1;
	public static final int McType_McVideo = 2;
	public static final int McType_McData = 4;
	public static final int McType_All = McType_McPtt | McType_McVideo | McType_McData;

	public static final int ShowViewType_Activity = 1;
	public static final int ShowViewType_FloatWindow = 2;

	public static final int CallType_Chat = 1;
	public static final int CallType_Prearranged = 2;

	public static final int CallType_Private = 3;
	public static final int CallType_Pull_One_To_One = 4;
	public static final int CallType_Pull_One_To_Svr = 5;
	public static final int CallType_Push_One_To_One = 6;
	public static final int CallType_Push_One_To_Svr = 7;
	public static final int CallType_Ambient_Listening = 8;
	public static final int CallType_Ambient_Viewing = 9;

	private String callIdStr = DEF_CALL_ID_STR;
	private AddrInfo groupInfo = null;
	private AddrInfo called = null;
	private int callDir;
	protected int callType = CallType_Private;
	protected boolean hasVideo = false;
	protected boolean isEmergency = false;
	private String funcName = null;
	private String locationStr = null;




	public CallAttr(int callType,AddrInfo called,int callDir,boolean useVideo,boolean isEmergency,String funcName,String locationStr)
	{
		this.callIdStr = DEF_CALL_ID_STR;
		this.callType = callType;
		this.called = called;
		this.callDir = callDir;
		this.hasVideo = useVideo;
		this.isEmergency = isEmergency;
		this.funcName = funcName;
		this.locationStr = locationStr;
	}

	public CallAttr(AddrInfo groupInfo,AddrInfo called,int callDir,boolean isGroup,boolean hasVideo,boolean isEmergency,String funcName,String locationStr)
	{
		Log.e(THIS_FILE, "CallAttr isGroup = " + isGroup + " funcName = " + funcName);
		this.callIdStr = DEF_CALL_ID_STR;
		//		this.mcType = McType_PTT;
		this.groupInfo = groupInfo;
		this.called = called;
		this.callType = CallType_Prearranged;
		this.callDir = callDir;
		this.hasVideo = hasVideo;
		this.isEmergency = isEmergency;
		this.funcName = funcName;
		this.locationStr = locationStr;
	}

	public String getCallKey()
	{
		if(callType == CallType_Prearranged
				|| callType == CallType_Chat)
		{
			return groupInfo.getAddrId();
		}
		else
		{
			return called.getAddrId();
		}
	}


	public void updateCallIdStr(String callIdStr)
	{
		this.callIdStr = callIdStr;
	}
	public String getCallIdStr() {
		return callIdStr;
	}

	//    public int getMcType() {
	//		return mcType;
	//	}
	//    
	//    public boolean isMcVideo()
	//    {
	//    	if(McType_VIDEO == mcType)
	//    	{
	//    		return true;
	//    	}
	//    	return false;
	//    }

	public int getCallType() {
		return callType;
	}

	public int getCallDir() {
		return callDir;
	}

	public boolean isMoCall()
	{
		if(CallDir_MO == callDir)
		{
			return true;
		}
		return false;
	}

	public AddrInfo getCalled() {
		return called;
	}

	public AddrInfo getCallLogAddrInfo(McIdInfo mcId)
	{
		if(CallDir_MT == callDir)
		{
			return called;
		}
		else
		{
			return mcId.toAddrInfo();
		}
	}

	public AddrInfo getGroupInfo() {
		return groupInfo;
	}

	public LaunchCallInfo toLaunchCallInfo(boolean isDac, int callState, int callMediaState, boolean micEnabled)
	{
		return new LaunchCallInfo(getCallKey(),callIdStr,callType,callDir,isDac,callState,callMediaState,micEnabled, hasVideo,isEmergency);
	}

	public boolean isHasVideo() {
		return hasVideo;
	}
	public boolean isEmergency() {
		return isEmergency;
	}
	public String getFuncName() {
		return funcName;
	}
	public String getLocationStr() {
		return locationStr;
	}
	public boolean isSendNegotiate()
	{
		Log.d(THIS_FILE, "isSendNegotiate callType = " + callType);
		Log.d(THIS_FILE, "isSendNegotiate callDir = " + callDir);
		return false;
	}

	public boolean isGroupCall()
	{
		if(callType == CallAttr.CallType_Prearranged
				|| callType == CallAttr.CallType_Chat)
		{
			return true;
		}
		return false;
	}

	public static boolean isGroupCall(int callType)
	{
		if(callType == CallAttr.CallType_Prearranged
				|| callType == CallAttr.CallType_Chat)
		{
			return true;
		}
		return false;
	}

	public boolean isPrivateCall()
	{
		if(callType == CallAttr.CallType_Private
				|| callType == CallAttr.CallType_Pull_One_To_One
				|| callType == CallAttr.CallType_Pull_One_To_Svr
				|| callType == CallAttr.CallType_Push_One_To_One
				|| callType == CallAttr.CallType_Push_One_To_Svr)
		{
			return true;
		}
		return false;
	}
	public boolean isAmbient()
	{
		if(callType == CallAttr.CallType_Ambient_Listening
				|| callType == CallAttr.CallType_Ambient_Viewing)
		{
			return true;
		}
		return false;
	}
	public boolean isAmbientListening()
	{
		if(callType == CallAttr.CallType_Ambient_Listening)
		{
			return true;
		}
		return false;
	}
	public boolean isAmbientViewing()
	{
		if(callType == CallAttr.CallType_Ambient_Viewing)
		{
			return true;
		}
		return false;
	}
	public static boolean isAmbient(int callType)
	{
		if(callType == CallAttr.CallType_Ambient_Listening
			|| callType == CallAttr.CallType_Ambient_Viewing)
		{
			return true;
		}
		return false;
	}

	public static boolean isAmbientViewing(int callType)
	{
		if(callType == CallAttr.CallType_Ambient_Viewing)
		{
			return true;
		}
		return false;
	}

	public static boolean isPrivateCall(int callType)
	{
		if(callType == CallAttr.CallType_Private
				|| callType == CallAttr.CallType_Pull_One_To_One
				|| callType == CallAttr.CallType_Pull_One_To_Svr
				|| callType == CallAttr.CallType_Push_One_To_One
				|| callType == CallAttr.CallType_Push_One_To_Svr)
		{
			return true;
		}
		return false;
	}
//	public static boolean isPrivateVoideoCall(int callType)
//	{
//		if(callType == CallAttr.CallType_Private
//				|| callType == CallAttr.CallType_Pull_One_To_One
//				|| callType == CallAttr.CallType_Pull_One_To_Svr
//				|| callType == CallAttr.CallType_Push_One_To_One
//				|| callType == CallAttr.CallType_Push_One_To_Svr)
//		{
//			return true;
//		}
//		return false;
//	}
	public static boolean isPushCall(int callType)
	{
		if(callType == CallAttr.CallType_Push_One_To_One
				|| callType == CallAttr.CallType_Push_One_To_Svr)
		{
			return true;
		}
		return false;
	}
	public static boolean isPullCall(int callType)
	{
		if(callType == CallAttr.CallType_Pull_One_To_One
				|| callType == CallAttr.CallType_Pull_One_To_Svr)
		{
			return true;
		}
		return false;
	}

	public String toString() 
	{
		StringBuffer strBuff = new StringBuffer("CallAttr:");
		strBuff.append("callKey = ").append(this.getCallKey()).append(",");
		strBuff.append("callIdStr = ").append(callIdStr).append(",");
		strBuff.append("callType = ").append(callType).append(",");
		strBuff.append("callDir = ").append(callDir).append(",");
		strBuff.append("called = ").append(called).append(",");
		strBuff.append("hasVideo = ").append(hasVideo).append(",");
		strBuff.append("isEmergency = ").append(isEmergency).append(",");
		strBuff.append("funcName = ").append(funcName).append(",");
		strBuff.append("locationStr = ").append(locationStr).append(",");
		strBuff.append("groupInfo = ").append(groupInfo).append(".");

		return strBuff.toString();
	}
}
